//
// Created by jiangpenghui on 2023/3/27.
//

#ifndef CMAKECXX_HOWMANY2_H
#define CMAKECXX_HOWMANY2_H

#include <string>
#include <iostream>

using namespace std;

class HowMany2 {
    string name;
    static int objectCount;
public:
    // 语法  成员变量初始化时赋值
    HowMany2(const string &id = "") : name(id) {
        ++objectCount;
        print("HowMany()");
        cout << "Name is :" << name << endl;
        cout << "id is :" << id << endl;
    };

    // 引用传参
    void print(const string &string) {
        if (string.size() != 0) {
            cout << string << endl;
            cout << '\t' << name << ": " << "ObjectCount =" << objectCount << endl;
        }
    }

    // run 2
    HowMany2(const HowMany2 &h) : name(h.name) {
        name += " Copy";
        ++objectCount;
        cout << h.name << endl;
        print("HowMany2 (const HowMany2&");
    }

    // 异构函数
    ~HowMany2() {
        cout << "this->name :" << name << endl;
        cout << " ~HowMany2" << endl;
    }
};

HowMany2 f(HowMany2 x);

#endif //CMAKECXX_HOWMANY2_H
